from flask import jsonify
from functools import wraps
from common.reponse.result import Result

"""
response body decorator
类似于 SpringMVC 中的 @ResponseBody

Copyright (C) chengpeng.hu. All Rights Reserved

@Author : chengpeng.hu
@Date : 2024
"""


def response_body(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        result = func(*args, **kwargs)
        if isinstance(result, Result):
            return result.to_json()
        return jsonify(result)

    return wrapper
